import prompt from '@system.prompt';
import router from '@system.router';
export default {
    data:{

            num: 5,
            index:Math.floor(Math.random()*5),
            indexArray:[],
            goon:0,
            signal:0,
            count:0,
            againcountright:1,
            againcountwrong:1,
//            题目内容及答案
            text1: [ {
                         ques: "室内不易于形成避震空间的地方是",
                         cho:["桌下、结实牢固的家具附近",
                         "内墙墙根、墙角",
                         "厨房、卫生间、储藏室等开间小、有管道支撑的地方",
                         "客厅、大厅等开间大的地方"
                         ],
                         ans:3
                     },
                     {
                         ques: "乘坐正在行驶的电（汽）车内遇到地震时，（）",
                         cho:["跳车",
                         "要降低重心，躲在座位附近，等地震过去后再下车",
                         "站在原地拉紧扶手，等地震过去后再下车",
                         "坐在原位不动，等地震过去后再下车"
                         ],
                         ans:1
                     },
                     {
                         ques: "违反防震减灾法规定，构成犯罪的，依法追究（）",
                         cho:["民事责任",
                         "法律责任",
                         "行政责任",
                         "刑事责任"
                         ],
                         ans:3
                     },
                     {
                         ques: "避震时用双手、书包或其他物品保护头部，并注意用衣物掩住口鼻。",
                         cho:["对",
                         "错"
                         ],
                         ans:0
                     },
                     {
                         ques: "地震时引发的（）次生灾害最严重。",
                         cho:["火灾",
                         "海啸",
                         "瘟疫",
                         ],
                         ans:0
                     },

            ],
//            题目乱序及选项乱序
            rand:function(){
                this.againcountright=1;
                this.againcountwrong=1;
                while(this.goon==0){
                    this.signal=0;
                    var chu=Math.floor(Math.random()*5);
                    for (var i=0; i<this.indexArray.length; i++)
                    {
                        if(chu==this.indexArray[i]){
                            this.signal=1;
                            break;
                        }
                    }
                    if(this.signal==0){
                        this.index=chu;
                        this.indexArray.push(chu);
                        this.goon=1;
                    }
                }
            },
//            若回答正确，执行此函数
            select_respondY:function(){
                console.log("Yes");
                if(this.againcountright==1){
                    this.$app.$def.globalData.rightNum=this.$app.$def.globalData.rightNum+1;
                }
                prompt.showToast({
                    message: '回答正确',
                    duration: 1000,
                });
                this.count=this.count+1;
                if(this.count==1){
                    this.indexArray.push(this.index);
                }

                if(this.indexArray.length<5){
                    this.goon=0;
                    this.rand();
                }else{
//                    router.back();
                    prompt.showToast({
                        message: '恭喜！已完成本轮任务',
                        duration: 2000,
                        bottom:50
                    });
                    setTimeout(()=>{
                        router.push({
                            uri:'pages/questiontype/endtest/endtest',
                        })
                    },2000);
                }
            },
//        若回答错误，执行此函数
            select_respondN:function(){
                console.log("No");
                this.againcountright=0;
                if(this.againcountwrong==1){
                    this.$app.$def.globalData.wrongNum=this.$app.$def.globalData.wrongNum+1;
                }
                this.againcountwrong=0;
                prompt.showDialog({
                    title: '提示信息',
                    message: '回答错误',
                    buttons: [
                        {
                            text: '再想想',
                            color: '#666666',
                        },
                        {
                            text: '退出做题',
                            color: '#666666',
                        },
                    ],
                    success: function(data) {
                        //                     console.log('dialog success callback，click button : ' + data.index);
                        if(data.index==1){
                            router.push({
                                uri:'pages/questiontype/endtest/endtest'
                            })
                        }

                    },
                    cancel: function() {
                        console.log('dialog cancel callback');
                    },
                });
            }


    },
    //响应结束答题 跳转到总结界面
    select_over(){
        router.push({
            uri:'pages/questiontype/endtest/endtest'
        })
    },
    select1(){
        if(this.text1[this.index].ans==0){
            this.select_respondY();
        }else{
            this.select_respondN();
        }
    },
    select2(){
        if(this.text1[this.index].ans==1){
            this.select_respondY();
        }else{
            this.select_respondN();
        }
    },
    select3(){
        if(this.text1[this.index].ans==2){
            this.select_respondY();
        }else {
            this.select_respondN();
        }
    },
    select4(){
        if(this.text1[this.index].ans==3){
            this.select_respondY();
        }else {
            this.select_respondN();
        }
    },
}
